package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.javaBean.wisdomParty.PartyInterFlowListBean;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class InterflowPingLunAdapter extends BaseAdapter {

    private Context context;
    private List<PartyInterFlowListBean> messageBeen;
    private LayoutInflater mInflater;

    public InterflowPingLunAdapter(Context context, List<PartyInterFlowListBean> messageBeen) {
        this.context = context;
        this.messageBeen = messageBeen;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return messageBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return messageBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_interpinglunflow, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        bindListItem(holder, position);//控制视图显示数据
        return convertView;
    }

    //控制视图显示数据
    private void bindListItem(ViewHolder holder, int pos) {
        PartyInterFlowListBean partyInterFlowListBean=messageBeen.get(pos);
        Glide.with(context).load(partyInterFlowListBean.getHeadImg())
                    .placeholder(R.mipmap.own_pic_logout)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(holder.civ_userphoto);
        holder.tv_username.setText(partyInterFlowListBean.getCreateUserName());
        String date_time = Tools.timedate(String.valueOf(partyInterFlowListBean.getCreateTime() / 1000));
        holder.tv_time.setText(date_time);
        holder.tv_title.setText(partyInterFlowListBean.getContent());

    }

    public class ViewHolder {
        private TextView tv_title;//图片
        private TextView tv_username;//标题
        private TextView tv_time;//时间
        private CircleImageView civ_userphoto;//来源

        public ViewHolder(View view) {
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_username = (TextView) view.findViewById(R.id.tv_username);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
            civ_userphoto = (CircleImageView) view.findViewById(R.id.civ_userphoto);
        }
    }

}
